#include "bproxy_api.h"

using namespace std;

#define     VERSION     "1.1.1"

int handle_init(int argc, char ** argv)
{
    SetVersion(VERSION);
    return 0;
}

void handle_fini(void)
{
    printf("handle_fini \n");
}

int handle_open(ConnectInfo* pCInfo)
{
    printf("handle_open|clientIP:%s \n" , pCInfo->clientIP.c_str());
    return 0;
}

int handle_close(ConnectInfo* pCInfo)
{
    printf("handle_close|clientIP:%s \n" , pCInfo->clientIP.c_str());
    return 0;
}

int handle_input(const char *buf, int bufLen, ConnectInfo* pCInfo, int* proxyFlag)
{
    printf("handle_input|buf:%s|bufLen:%d \n" , buf , bufLen);
    *proxyFlag = 1;
    return bufLen;
}

int handle_process(const char *pkgBuf, int pkgLen, ConnectInfo* pCInfo)
{
    printf("handle_procss|buf:%s \n" , pkgBuf);
    
    char p[20] = "test111";
    SendToClient(pCInfo->fd , p , strlen(p));
    return 0;
}

int handle_input_buf(const char *pkgBuf, int pkgLen, ConnectInfo* pCInfo)
{
    printf("handle_input_buf|buf:%s \n" , pkgBuf);

    return SendToServer(pCInfo->fd , pkgBuf , pkgLen);
}

int handle_output(const char *buf, int bufLen, ConnectInfo* pCInfo)
{
    printf("handle_output \n");
    return bufLen;
}

int handle_output_buf(const char *pkgBuf, int pkgLen, ConnectInfo* pCInfo)
{
    printf("handle_input_buf \n");

    return SendToClient(pCInfo->fd , pkgBuf , pkgLen);
}

int handle_proxy_ip(ConnectInfo* pCInfo, std::string* ip, int* port)
{
    printf("handle_proxy_ip \n");
    *ip   = "127.0.0.1";
    *port = 12341;
    return 0;
}

int handle_proxy_open(ConnectInfo* pCInfo)
{
    printf("handle_proxy_open \n");
    return 0;
}
